package com.wen.design.controller;

import com.wen.design.entity.enums.PayTypeEnum;
import com.wen.design.right.PayFactory;
import com.wen.design.service.PayService;
import com.wen.design.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/pay")
public class PayController {
//    @Resource
//    private PayFactory payFactory;
    private PayService payService;
    @RequestMapping("/procedurePay/{productId}/{payType}")
    public R procedurePay(@PathVariable Long productId,@PathVariable String payType) {
        log.info("开始下单咯！");
        log.info("payType:{}",payType);
        PayTypeEnum payTypeEnum = PayTypeEnum.getPayType(payType);
        payService = PayFactory.getPayService(payTypeEnum);
        Map<String, Object> map = payService.procedurePay(productId);
        return R.ok().setData(map);
    }


    @PostMapping("/procedurePay/notify")
    public R procedurePayNotify(HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> map =payService.procedurePayNotify(request,response);
        return R.ok().setData(map);
    }
}
